package handlers

import (
	"github.com/gin-gonic/gin"
	"user-mng-sys/models"
)

func Create(c *gin.Context) {
	uid := c.PostForm("uid")
	name := c.PostForm("name")

	if uid == "" || name == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "数据不能为空",
		})
		return
	}

	data := models.Role{
		Uid:  uid,
		Name: name,
	}

	err := models.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 500,
		"msg":  "添加成功",
	})
	return
}
